#!/bin/bash

# 停止MySQL服务
systemctl stop mysqld

# 以跳过授权表的方式启动MySQL
mysqld_safe --skip-grant-tables &

# 等待MySQL启动
sleep 5

# 重置root密码
mysql -u root << EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
EOF

# 停止MySQL
killall mysqld

# 重启MySQL服务
systemctl start mysqld

echo "MySQL root password has been reset to 123456" 